﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System.Linq;
using Microsoft.WVB.Server;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.WVB.UnitTest.Server
{
    /// <summary>
    /// Summary description for EntityModelProvisioning
    /// </summary>
    [TestClass]
    public class EntityModelProvisioning
    {
        private int bMax = 0, cMax = 0, pMax = 0;
        private WVBDataModel epg;

        public EntityModelProvisioning()
        {
            //
            // TODO: Add constructor logic here
            //
            string cxn = "metadata=res://*/EPGDataModel.csdl|res://*/EPGDataModel.ssdl|res://*/EPGDataModel.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=.\\SQLEXPRESS;Initial Catalog=EPGDataServicesDb;Integrated Security=True;MultipleActiveResultSets=True;\"";

            epg = new WVBDataModel(cxn);

            bMax = (from b in epg.Broadcasters
                    select b.id).Max();

            cMax = (from c in epg.Channels
                    select c.cid).Max();

            pMax = (from p in epg.Programs
                    select p.programid).Max();           
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ProvisionHierarchy()
        {
            Broadcaster RTVE = Broadcaster.CreateBroadcaster("RTVE", ++bMax);
            RTVE.Website = "http://www.rtve.com";
            RTVE.Icon = "http://localhost:8080/Media/Broadcasters/CUATRO.png";

            epg.AddToBroadcasters(RTVE);

            Broadcaster Telecinco = Broadcaster.CreateBroadcaster("Telecinco", ++bMax);
            Telecinco.Website = "http://www.Telecinco.com";
            Telecinco.Icon = "http://localhost:8080/Media/Broadcasters/ORANGE.png";

            epg.AddToBroadcasters(Telecinco);

            Broadcaster CNN = Broadcaster.CreateBroadcaster("CNN", ++bMax);
            CNN.Website = "http://www.CNN.com";
            CNN.Icon = "http://localhost:8080/Media/Broadcasters/NETTV.png";

            epg.AddToBroadcasters(CNN);

            Broadcaster ANTENA3 = Broadcaster.CreateBroadcaster("ANTENA3", ++bMax);
            ANTENA3.Website = "http://www.ANTENA3.com";
            ANTENA3.Icon = "http://localhost:8080/Media/Broadcasters/VEO.png";

            epg.AddToBroadcasters(ANTENA3);

            Channel TVE = Channel.CreateChannel(++cMax, "TVE", "TVE Channel");
            TVE.Icon = "http://localhost:8080/Media/Channels/24HTVE.png";
            RTVE.Channels.Add(TVE);

            epg.AddToChannels(TVE);

            epg.SaveChanges();

        }
    }
}
